<?php
/**
* 
*/
class RegisterView
{
	// Hjälper att ta bort sträng beronde 
	private $newUname = "newUname";
	private $newPword = "newPword";
	private $samePword = "samePword";
	private $register = "register";
	//constanter för att skriva ut fel
	const ALL_PASS_WRONG = 0;
	const EMPTY_FIELD = 1;
	const USER_USED = 2;
	const WRONG_PASS_FORMAT =3;
	const REG_ACCEPT = 4; 
	// funktion som innehåller ett form 
	function DoRegisterBox()
	{
		$html =
			"<H3>register</h3>
				<form method='post' action='index.php?page=register'>
					Username:
						<input type='text' name=' $this->newUname' /><p></p>
					Password:
						<input type='password' name='$this->newPword' /><p></p>
					Reenter password:
						<input type='password' name='$this->samePword' /><p></p>
					<input type='submit' value='Register' name='$this->register'/>
				</form>";
			return $html;
	}
	// de två funktionerna nedan "postar" användar namnet och lösenorden
	function PostUserName()
	{
		if (isset($_POST[$this->newUname]) == true)
		{
			return $_POST[$this->newUname];
		}
		return null;
	}
	function PostPassword()
	{
		if (isset($_POST[$this->newPword]) == true)
		{
			return $_POST[$this->newPword];
		}
		return null;
	}
	function PostSamePass()
	{
		if (isset($_POST[$this->samePword])== true)
		{
			return $_POST[$this->samePword];
		}
		return false;
	}
	// knappen för att registrera 
	function TriedToRegister()
	{ 
		if (isset($_POST[$this->register]) == true) 
		{
			return true;
		}
		return false;
	}
	//skapar fel meddelande 
	public function Message($status)
	{
			switch ($status) {
			case self::ALL_PASS_WRONG :
				return "<p><i>Password needs to be the same in both fields.</i></p>";
				break;
			case self::EMPTY_FIELD:
				return "<p><i>All fields needs to be filled.</i></p>";
				break;
			case self::USER_USED:
				return "<p><i>Username taken.</i></p>";
				break;
			case self::WRONG_PASS_FORMAT:
				return "<p><i>Password needs 6 charecters and whithold 1 number and only lowercase letters .</i></p>";
				break;
			case self::REG_ACCEPT:
				return "<p><i>Youre registration was succesfull.</i></p>";
				break;
			default:
			break;
		}

	}
}
?>